package com.atguigu.flink.chapter10;

import com.atguigu.flink.bean.WaterSensor;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.types.Row;

import static org.apache.flink.table.api.Expressions.$;

public class TableApiDemo3 {
    public static void main(String[] args) throws Exception {
        //表的执行
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Tuple2<String, Long>> stream = env.fromElements(
                Tuple2.of("a", 1L),
                Tuple2.of("b", 2L)
        );

        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        //Table table = tEnv.fromDataStream(stream, $("word"), $("count"));

        Schema schema = Schema.newBuilder()
                .column("f0", DataTypes.STRING())
                .column("f1", DataTypes.BIGINT())
                .build();
        Table table = tEnv.fromDataStream(stream, schema);

        table.printSchema();

    }
}


//public class TableApiDemo3 {
//    public static void main(String[] args) {
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(1);
//
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//
//        DataStreamSource<Tuple2<String, Long>> source = env.fromElements(
//                Tuple2.of("a", 1L),
//                Tuple2.of("b", 2L)
//        );
//
//        Schema schema = Schema.newBuilder()
//                .column("f0", DataTypes.STRING())
//                .column("f1", DataTypes.BIGINT())
//                .build();
//
//        Table table = tEnv.fromDataStream(source, schema);
//        table.printSchema();
//    }
//}

//public class TableApiDemo3 {
//    public static void main(String[] args) {
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(1);
//
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//
//        DataStreamSource<Tuple2<String, Long>> source = env.fromElements(
//                Tuple2.of("a", 1L),
//                Tuple2.of("b", 1L)
//        );
//
//        Schema schema = Schema.newBuilder()
//                .column("f0", DataTypes.STRING())
//                .column("f1", DataTypes.BIGINT())
//                .build();
//
//        Table table = tEnv.fromDataStream(source, schema);
//        table.printSchema();
//    }
//}


//public class TableApiDemo3 {
//    public static void main(String[] args) {
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//        env.setParallelism(1);
//
//        DataStreamSource<Tuple2<String, Long>> source = env.fromElements(
//                Tuple2.of("a", 1L),
//                Tuple2.of("b", 1L)
//        );
//
//        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
//
//        Schema schema = Schema.newBuilder()
//                .column("f0", DataTypes.STRING())
//                .column("f1", DataTypes.BIGINT())
//                .build();
//
//        Table table = tEnv.fromDataStream(source, schema);
//        table.printSchema();
//    }
//}